
NET.addAssembly('C:\Development\MatlabPeakFinder_mySQL\cSharpDLL\mySQLAdapter.dll');

switch computer
    case 'PCWIN'
        dlldir = fullfile(pwd,'dlls','bin','32-bit','nilibddc.dll');
        headerdir = fullfile(pwd,'dlls','include','32-bit','nilibddc_m.h');
    case 'PCWIN64'
        dlldir = fullfile(pwd,'dlls','bin','64-bit','nilibddc.dll');
        headerdir = fullfile(pwd,'dlls','include','64-bit','nilibddc_m.h');
end

disp(dlldir)
disp(headerdir)

if ~libisloaded('nilibddc')
    try
        % loadlibrary(dlldir,headerdir);
        loadlibrary(dlldir, @nilibddc, 'alias', 'nilibddc')
    catch %#ok<CTCH>
        warndlg({'Cannot load libraries to read TDMS files!',...
            'You can continue to use the program but it won''t read TDMS files,',...
            'you probably need to install a compiler in MATLAB.',...
            'Google "MATLAB Selecting a Compiler on Windows Platforms"',...
            'Or Talk to Brett Gyarfas!'},'Error!','modal')
    end
end


%load the setting file and the data folders
disp('===============================')
disp('LoadingXLSParameters')
[folderPaths runParams]=  LoadXLSParameters('S:\Research\Brian\FlowThrough.xlsx','FlowThrough');
disp('===============================')



%if exist('conn','var')==false
conn=database('recognition','honcho','12Dnadna');
setdbprefs('DataReturnFormat','structure');
%end
if (false)
    SaveFolders(folderPaths, runParams, false,false, conn );
    SaveFolders(folderPaths, runParams, false,true, conn );
    
    [experiment_Index, analyteList ]=LoadData2(folderPaths, runParams, false, conn );
    
    
    [colNames,dataTable controlTable]=GetDataTablesSQL(conn,experiment_Index);
    [colNames,dataTable, controlTable]=ScaleData2(colNames,dataTable, controlTable);
    % %remove the datapoints that are correlated.  They slow down the processing
    % %and screw up the svm
    % %this also converts the data to its final form in the tables
    [colNames,dataTable, controlTable] = CovarianceClean(colNames,dataTable, controlTable, .85);
    %
    %
    refinedData.experiment_Index = experiment_Index;
    refinedData.colNames = colNames ;
    refinedData.dataTable = dataTable;
    
    
    % % %the water signal is set up with a one class SVM, anything that falls
    % % %inside the one class is removed.
    if (runParams.Remove_Water==1 && isempty(controlTable)==false  )
        disp('===============================');
        disp('Removing Water Signal');
        [refinedData]= RemoveWater(conn,refinedData,controlTable,runParams);
    end
    
    disp('===============================');
    disp('Cross Validation and Grid search');
    SVMParams=CrossValidate(experiment_Index,refinedData.dataTable, refinedData.colNames,runParams);
end


disp('Running Parameter Search');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

AdaptiveFeatureSelectionSearch(experiment_Index,conn, refinedData,  runParams, SVMParams )


%  [colNames,dataTable,controlTable ] = GoodParameters( colNames,dataTable, controlTable, runParams );
%    
% [ extraInfo2]=  RandomSearch(superIteration,expName,reorganizedGroups,runParams,SVMParams,extraInfo);
% end

disp('===============================')

